<?php
/**
 * Created by PhpStorm.
 * User: Celebration-Grey
 * Date: 2017/5/9
 * Time: 17:41
 */

namespace App\Http\Classes;


class Background extends Image
{
    private $dst;
    private $url;

    public function setDst()
    {
        // TODO: Implement setDst() method.
        $root = 'weiboimg/background/';
        $this -> dst = $root.'background_1366/'.$this->name.$this->extension;
    }

    public function setUrl()
    {
        // TODO: Implement setUrl() method.
        $this -> url = $this -> host . $this -> dst;
    }

    public function setOriginal()
    {
        // TODO: Implement setOriginal() method.
        $this -> original = 'weiboimg/background/original/';
    }

    public function updateUser()
    {
        // TODO: Implement updateUser() method.
        $this -> setUrl();
        $user = new User($_COOKIE['user_id']);
        $user = $user -> updateBackground($this->url);
        if($user){
            $this -> code = 200;
            $this -> msg = 'Head image saved and update success!';
        }
        else{
            $this -> code = 304;
            $this -> msg = 'Head image saved but update error!';
        }
    }

    public function getResult()
    {
        // TODO: Implement getResult() method.
        $data = [];
        $data['big'] = $this -> url;
        return $data;
    }

    public function howCrop($data, $src_img, $src_img_w, $src_img_h)
    {
        // TODO: Implement howCrop() method.
        $this -> croppedSize(1366,760,$data,$this->dst,$src_img,$src_img_w,$src_img_h);
    }
}